package entity

import (
	"fmt"
	"time"

	"gorm.io/gorm"
	"shqsoft.cn/pas3ui/base"
)

//ShIndiJjzsdr2 中收（私行）
type ShIndiJjzsdr2 struct {
	JLID  int       `gorm:"AUTO_INCREMENT;primary_key;column:JLID"`
	EMID  int       `gorm:"column:EMID"`
	EMNO  string    `gorm:"column:EMNO"`  //员工号
	EMNM  string    `gorm:"column:EMNM"`  //员工名
	ZS    float64   `gorm:"column:ZS"`    //中收
	DRRQ  time.Time `gorm:"column:DRRQ"`  //业绩统计日期
	CZRID int       `gorm:"column:CZRID"` //操作人ID
	CZR   string    `gorm:"column:CZR"`   //操作人
	CZRQ  time.Time `gorm:"column:CZRQ"`  //操作日期
}

//TableName
func (ShIndiJjzsdr2) TableName() string {
	return "SH_INDI_JJZSDR2"
}

// BeforeCreate
func (u *ShIndiJjzsdr2) BeforeCreate(tx *gorm.DB) (err error) {
	var emid *int
	tx.Raw(`select "ID" from "T_SysUser" where "SysUserID" = ?`, u.EMNO).Row().Scan(&emid)
	if emid == nil {
		err = fmt.Errorf("员工号%s在系统中不存在！", u.EMNO)
		return
	}
	u.EMID = *emid
	u.CZRQ = time.Now()
	return
}

//ShIndiJjzsdr2EF 返回结构体
func ShIndiJjzsdr2EF() base.EntityFunc {
	return func() interface{} {
		entity := ShIndiJjzsdr2{}
		return &entity
	}
}

//ShIndiJjzsdr2ESF 返回结构体数组
func ShIndiJjzsdr2ESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []ShIndiJjzsdr2
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("ShIndiJjzsdr2", base.NewDefaultDao(ShIndiJjzsdr2EF(), ShIndiJjzsdr2ESF(), nil, "my"))
}
